package com_.dxy_test_.socket_;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

/**
 * @Description 客户端
 * @Author dangxianyue
 * @Date 2022/9/26 17:42
 */
public class Client {

    public static void main(String[] args) throws IOException {
        try (
                Socket s = new Socket("127.0.0.1", 9000);
                Scanner in = new Scanner(s.getInputStream(), "utf-8")
        ) {
            while (in.hasNextLine()) {
                String line = in.nextLine();
                System.out.println(line);
            }
        } catch (IOException e) {
            /*如果存在host 不存在之外的异常会抛出一个IOException 异常
             * UnknownHostException是这个异常的子异常
             * */
            e.printStackTrace();
        }

    }
}
